﻿using System;
using Common;
using IBll.Sys;
using Model.Sys.Config;
using Model.Sys.Constant;

namespace Bll.Sys
{
    public class SiteConfigBll : ISiteConfigBll
    {
        private static readonly object LockHelper = new object();

        public void SaveConfig(SiteConfig config, string configPath)
        {
            try
            {
                lock (LockHelper)
                {
                    SerializeHelper.XmlSerialize(config, configPath);
                    ICacheBll cacheBll = IocHelper.AutofacResolve<ICacheBll>();
                    cacheBll.Update(Constant.CacheKey.SiteConfigCacheKey, config);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            
        }

        public SiteConfig LoadConfig(string configPath)
        {
            return (SiteConfig)SerializeHelper.XmlDeSerialize(typeof(SiteConfig), configPath);
        }
    }
}
